import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import Login from '../components/login.vue'
import Home from '../components/home.vue'

import StudentManagement from '../components/main/StudentManagement.vue'
import publishTest from '../components/Test/publishTest.vue'
import publishTest2 from '../components/Test/publishTest2.vue'

import publicChoose from '../components/questions/publicChoose.vue'
import publicEncode from '../components/questions/publicEncode.vue'
import publicFillEmpty from '../components/questions/publicFillEmpty.vue'
import publicJudge from '../components/questions/publicJudge.vue'
import gradesView from '@/components/grades/gradesView.vue'
import gradingWork from '@/components/grading/gradingWork.vue'
import sign from '@/components/sign/sign.vue'
import employee from '@/components/employee/employee.vue'

import ppt from '../components/ppt/ppt.vue'

Vue.use(VueRouter)
const routes = [
  { path: '/', redirect: '/login'},
  { path: '/login', component: Login},
  { path: '/home',
    component: Home,
    // edirect: '/StudentManagement',//默认指向
    children:[
      { path: '/sign', component: sign},// 签到列表
      { path: '/', redirect: '/StudentManagement'},//一进入就打开这个页面
      { path: '/StudentManagement',component: StudentManagement},
      // 这个是发布测试的两个路由
      { path: '/publishTest', component: publishTest},
      { path: '/publishTest2', component: publishTest2},
      //这个是公共题库的四个路由
      { path: '/publicChoose',component: publicChoose},
      { path: '/publicEncode',component: publicEncode},
      { path: '/publicFillEmpty',component: publicFillEmpty},
      { path: '/publicJudge',component: publicJudge},
      { path: "/ppt", component: ppt},

      // 成绩查询
      { path: "/gradesView", component: gradesView},

      // 批改试卷
      { path: "/gradingWork", component: gradingWork},

      // 员工查询
      { path: "/employee", component: employee}
  ]},
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  //     next()  放行    next('/login')  强制跳转

  if (to.path === '/login') return next()
  // 获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
